package org.apache.ibatis.demo.generator;

import java.util.Random;

/**
 * IdCardGenerator
 *
 * @author zhaohui
 * @date 2019/12/12 17:53
 */
public class IdCardGenerator {

    private static final Random random = new Random();

    private static final int ID_CARD_LENGTH = 18;

    private static final int ID_CARD_SPECIAL_CHAR_LENGTH = 2;

    public static String randomIdCard() {
        StringBuilder sf = new StringBuilder();

        for (int i = 0; i < ID_CARD_LENGTH - 1; i++) {
            int index = random.nextInt(DataDict.ID_CARD_NUMBERS.length - ID_CARD_SPECIAL_CHAR_LENGTH);
            sf.append(DataDict.ID_CARD_NUMBERS[index]);
        }
        int index = random.nextInt(DataDict.ID_CARD_NUMBERS.length);
        sf.append(DataDict.ID_CARD_NUMBERS[index]);
        return sf.toString();
    }

}